﻿namespace EyeOpen.Security.Data.Test
{
	using System;
	using System.Linq;

	using EyeOpen.Security.Domain;

	using Microsoft.VisualStudio.TestTools.UnitTesting;

	using SharpTestsEx;

	[TestClass]
	public class SecurityUnitOfWorkTest
	{
		[TestInitialize]
		public void Initialize()
		{
			using (ISecurityUnitOfWork uow = new SecurityUnitOfWork())
			{
				if (uow.Database.Exists())
				{
					uow.Database.Delete();
				}

				uow.Database.Create();
			}
		}

		[TestMethod]
		public void SaveUserAndCheckExists()
		{
			const string Expected = "b@b.com";

			using (ISecurityUnitOfWork uow = new SecurityUnitOfWork())
			{
				uow.UserRepository.Add(new User { Id = Guid.NewGuid(), Email = Expected, Password = User.CreatePassword("password") });

				uow.Commit();
			}

			using (ISecurityUnitOfWork uow = new SecurityUnitOfWork())
			{
				var user = uow.UserRepository.Single();

				user
					.Email
					.Should()
					.Be
					.EqualTo(Expected);
			}
		}
	}
}